﻿ @model Tuple<DotaHelp.Controllers.PurchasesItemRuleAndComments[], DotaHelp.Controllers.PurchasesHeroRuleAndComments[]>

<h3>Ограничения для предметов: </h3>
<table>
 @foreach (var r in Model.Item1)
 { 
    <tr class="@r.Rule.Severity">
        
        <td style="width:80px;">@Html.Raiting("PurchasesRules", r.Rule.Id, r.Rule.Raiting, "RatingItemRule")<br />
         @Html.LinkOnItem(r.Item1, null, true) @Html.LinkOnItem(r.Item2, null, true)</td>
                    
        <td style="min-width:300px">@Html.ReplaceKeyOnContent(r.Rule.Text, true, true) @Html.EditDialog("PurchaseItemRules", "Text", r.Rule.Id, "")</td>
        <td>@Html.ShowUserName(r.Rule.Author)</td>
        <td>
            @Html.Action("CompactListForUrl", "Comments", new
       {
           url = "/ItemRule/" + r.Rule.Id,
           comments = r.Comments.ToArray()
       })   
        </td>
        @if (Request.IsAuthenticated)
        { 
                <td>                                
                          
                    @using (Html.BeginForm("RemoveItemRule", "PurchasesRules"))
                    {
                        <input type="hidden" name="id" value="@r.Rule.Id" /> 
                        <input type="submit" value="Удалить" />                                   
                    }
                    @using (Html.BeginForm("UpdateItemRuleSeverity", "PurchasesRules"))
                    {
                            <input type="hidden" name="id" value="@r.Item1.Id" />
                            <select name="severity"  style="width:80px" onchange='this.form.submit()'>
                                <option value='Critical' @(r.Rule.Severity == "Critical" ? "selected" : "")>Нельзя сохранить закуп с таким предметом</option>
                                <option value='Warning' @(r.Rule.Severity == "Warning" ? "selected" : "")>-10 рейтинга за нарушение</option>
                                <option value='Information' @(r.Rule.Severity == "Information" ? "selected" : "")>Информация</option>
                            </select>
                    }
                </td>
        }
    </tr>
 }
 @foreach (var r in Model.Item2)
{ 
    <tr class="@r.Rule.Severity">                            
        <td style="width:80px">@Html.Raiting("PurchasesRules", r.Rule.Id, r.Rule.Raiting, "RatingHeroRule")<br />
         @Html.LinkOnHero(r.Hero, true)
         @Html.LinkOnItem(r.Item, null, true)
        </td>                      
        <td style="min-width:300px">@Html.ReplaceKeyOnContent(r.Rule.Text, true, true) @Html.EditDialog("PurchaseHeroRules", "Text", r.Rule.Id, "")  </td>
        <td>@Html.ShowUserName(r.Rule.Author)</td>
        <td>
            @Html.Action("CompactListForUrl", "Comments", new
            {
                url = "/HeroRule/" + r.Rule.Id,
                comments = r.Comments.ToArray()
            })   
        </td>
        @if (Request.IsAuthenticated)
        { 
                <td>
                    @using (Html.BeginForm("RemoveHeroRule", "PurchasesRules"))
                    {
                        <input type="hidden" name="id" value="@r.Rule.Id" />
                        <input type="submit" value="Удалить" />                                   
                    }

                    @using (Html.BeginForm("UpdateHeroRuleSeverity", "PurchasesRules"))
                    {
                        <input type="hidden" name="id" value="@r.Rule.Id" />
                        <select name="severity" style="width:80px" onchange='this.form.submit()'>
                            <option value='Critical' @(r.Rule.Severity == "Critical" ? "selected" : "")>Нельзя сохранить закуп с таким предметом</option>
                            <option value='Warning' @(r.Rule.Severity == "Warning" ? "selected" : "")>-10 рейтинга за нарушение</option>
                            <option value='Information' @(r.Rule.Severity == "Information" ? "selected" : "")>Информация</option>
                        </select>
                    }
                </td>
        }
</tr>
}    
</table>

@if (Request.IsAuthenticated)
{
    using (Html.BeginForm("AddItemRule", "PurchasesRules"))
    { 
        <script type="text/javascript">
                function selectItem() {
                    $("#selectItemDialog").load("@Url.Action("SmallList", "Items")", function(){
                        $(".Item").bind("click", function(){
                                $("#selectItemDialog").dialog("close");
                                if ($("#item2Id").val() != "") $("#item2Id").val($("#item2Id").val() + ", ");
                                $("#item2Id").val($("#item2Id").val() + $(this).attr("itemid"));
                        });
                    });
                    $("#selectItemDialog").dialog({ autoOpen: true, modal: true, width: 800, height:450 });
                }
            </script>
             
        @Html.Hidden("item1Id", (int)ViewBag.ItemId)
        <span>Номер предмета:</span>  
        <input type="text" name="item2Id" style="width:70px" id="item2Id"
            data-val-required="Требуется указать номер запрещенного предмета." 
            data-val="true" 
            />
        <input type="button" value="..." onclick="selectItem();" />
            <div id="selectItemDialog" style="display:none"><noindex>Загрузка...</noindex></div>
        <select name="severity">
            <option value='Critical'>Нельзя сохранить закуп с таким предметом</option>
            <option value='Warning'>-10 рейтинга за нарушение</option>
            <option value='Information'>Информация</option>
        </select>
        <input type="submit" value="Добавить" />
        @Html.ValidationSummary();
        <div></div>   
        <textarea name="text" cols=50 rows=5 data-val-required="А как же описать правило?" data-val="true"></textarea>                    
    }
}